home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 1 / Gold Medal Software Volume 1 (Gold Medal) (1994).iso / prog / tpwprog6.arj / BUTTONU.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-07-02  |  2.7 KB  |  89 lines

  1. { buttonu.pas -- Check box and radio button unit }
  2.  
  3. unit ButtonU;
  4.  
  5. interface
  6.  
  7. uses WinTypes, WinProcs;
  8.  
  9. type
  10.  
  11.   CBSet = Set of 0 .. 15; { Set of up to 16 check boxes }
  12.   RadioSet = CBSet;       { Set of up to 16 radio buttons }
  13.  
  14. procedure SetChecks(HDlg: HWnd; C: CBSet; FirstID, LastID: Word);
  15. procedure SetRadios(HDlg: HWnd; R: RadioSet; FirstID, LastID: Word);
  16. procedure GetChecks(HDlg: HWnd; var C: CBSet; FirstID, LastID: Word);
  17.  
  18. implementation
  19.  
  20. {- Limit LastID to FirstID + 15 }
  21. procedure LimitIDs(FirstID: Word; var LastID: Word);
  22. var
  23.   MaxLastID: Word;
  24. begin
  25.   MaxLastID := FirstID + 15;
  26.   if LastID > MaxLastID
  27.     then LastID := MaxLastID
  28. end;
  29.  
  30. {- Set check boxes according to values in C for dialog HDlg. FirstID
  31. should be the ID of the first check box control in this series.
  32. LastID should be the ID of the last box in the series. }
  33.  
  34. procedure SetChecks(HDlg: HWnd; C: CBSet; FirstID, LastID: Word);
  35. var
  36.   I: Integer;
  37. begin
  38.   LimitIDs(FirstID, LastID);
  39.   for I := 0 to LastID - FirstID do
  40.     if I in C then
  41.       SendDlgItemMessage(HDlg, I + FirstID, bm_SetCheck, 1, 0)
  42. end;
  43.  
  44. {- Set radio buttons according to values in set R for dialog HDlg.
  45. The FirstID parameter must be the ID of the first radio button in
  46. this series. LastID must be the ID of the last button in the series.
  47. No radio button should have its Tabstop bit set in the resource,
  48. however the first radio button must have the group bit set. This
  49. configuration allows the input focus to move between groups for Tab
  50. and Shift+Tab, and within groups for Arrow keys. }
  51.  
  52. procedure SetRadios(HDlg: HWnd; R: RadioSet; FirstID, LastID: Word);
  53. var
  54.   I: Integer;
  55.   HControl: HWnd;
  56.   StyleBits: Word;
  57. begin
  58.   LimitIDs(FirstID, LastID);
  59.   for I := 0 to LastID - FirstID do if (I in R) then
  60.   begin
  61.     HControl := GetDlgItem(HDlg, FirstID + I);
  62.     SendMessage(HControl, bm_SetCheck, 1, 0);
  63.   end
  64. end;
  65.  
  66. {- Retrieve check box or radio button settings into C. }
  67. procedure GetChecks(HDlg: HWnd; var C: CBSet; FirstID, LastID: Word);
  68. var
  69.   I: Integer;
  70. begin
  71.   LimitIDs(FirstID, LastID);
  72.   C := [];
  73.   for I := 0 to LastID - FirstID do
  74.    if SendDlgItemMessage(HDlg, I + FirstID, bm_GetCheck, 0, 0) <> 0
  75.     then C := C + [I]
  76. end;
  77.  
  78. end.
  79.  
  80.  
  81. {--------------------------------------------------------------
  82.   Copyright (c) 1991 by Tom Swan. All rights reserved.
  83.   Revision 1.00    Date: 3/19/1991
  84.   Revision 1.01    Date: 11/1/1991
  85.   1, Removed following statements from SetRadios procedure
  86.      StyleBits := GetClassWord(HControl, gcw_Style);
  87.      SetClassWord(HControl, gcw_Style, StyleBits or ws_Tabstop)
  88. ---------------------------------------------------------------}
  89.